package nori6_common_protocol;

import nori6_common_protocol.Nori6Message.NORI6_CONTROLLER_TYPE;

public class Nori6UsersMessage 
{
	public enum NORI6_USERS_MESSAGE_TYPE
	{
		N6_USERS_LOGIN,
		N6_USERS_SIGNUP,
	};
	
	private Nori6IncomingMessage m_Msg;
	private String m_Username;
	private String m_Password;
	private NORI6_USERS_MESSAGE_TYPE m_Type;
	
	private static final String username_key = "username";
	private static final String password_key = "password";
	private static final String command_key = "cmd";
	
	public Nori6UsersMessage(Nori6IncomingMessage msg)
	{
		m_Msg = msg;
		m_Username = (String)m_Msg.GetField(username_key);
		m_Password = (String)m_Msg.GetField(password_key);
		
		long i = (long)m_Msg.GetField(command_key);
		m_Type = NORI6_USERS_MESSAGE_TYPE.values()[(int)i];
	}
	
	public String GetUsername()
	{
		return m_Username;
	}
	
	public String GetPassword()
	{
		return m_Password;
	}
	
	public NORI6_USERS_MESSAGE_TYPE GetType()
	{
		return m_Type;
	}
	
	static public String EncodeMessage(NORI6_USERS_MESSAGE_TYPE type, String username, String Password)
	{
		Nori6OutgoingMessage msg = new Nori6OutgoingMessage();
		msg.SetController(NORI6_CONTROLLER_TYPE.N6_USERS_CONTROLLER);
		msg.SetField(username_key, username);
		msg.SetField(password_key, Password);
		msg.SetField(command_key, type.ordinal());
		return msg.GetString();
	}
}
